package com.itheima.springbootmybatisdemo.controller;

import com.itheima.springbootmybatisdemo.pojo.EmpDTO;
import com.itheima.springbootmybatisdemo.pojo.EmpVO;
import com.itheima.springbootmybatisdemo.pojo.Result;
import com.itheima.springbootmybatisdemo.service.LoginService;
import com.itheima.springbootmybatisdemo.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 15 4月 2025 15:56
 */
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 登录
     *
     * @param empDTO
     * @return
     */
    @GetMapping("/login")
    public Result login(@RequestBody EmpDTO empDTO) {
        EmpVO empVO = loginService.login(empDTO);
        String token = JwtUtils.getToken(empVO.getId());
        empVO.setToken(token);
        return Result.success(empVO);
    }

}
